﻿#ifndef COMPUTERMANAGER_H
#define COMPUTERMANAGER_H

#include <QObject>
#include <QMutex>
#include "TcpServer.h"
#include "dbservice.h"
#include "computeralarmlog.h"
#include "apprunninginfo.h"
#include "getsystemrunningstateres.h"


class ComputerManager : public QObject
{
    Q_OBJECT
public:
    ComputerManager();

    void start();

    void stop();

    void onOfflineCheckTimerFired();

    QString getAlarmInfoOfComputer(Computer &computer);

    int saveOneComputer(Computer & computer);

    int saveOneComputerAlarmLog(ComputerAlarmLog &log);

    void deleteOneComputer(long id);

    void onClientReportStatus(SString ip, SString apps);

    //int getOneComputerByID(long id, Computer & computer);

    int getOneComputerByIP(SString ip, Computer &computer);

    QList<Computer>  getCopyOfComputers(bool onlyDisConnect = false, bool onlyUnreadAlarm = false);

    QList<Computer>  getCopyOfOnlineComputers(QString appName);

    int getAppRunningInfosFromIP(SString ip, list<AppRunningInfo> & apps);

    int getSystemRunningInfosFromIP(SString ip, list<DiskInfo> &lastDiskInfo,list<float> &lastCPUUsages,list<float> &lastMEMUsages);


    void onOneComputerAlarmLogsChanged(long computerId);

    bool checkAndSendAlarm();


signals:

    void computersUpdated();


    void offlineAndALarmCountUpdate(int offLineCount, int allComputerCount, int unreadAlarmCount);

public:

    TcpServer * server;

    MMRESULT checkOfflineTimer;



    QList<Computer> computers;

    QStringList appList;

    int offlineCount;


    QMutex lock;

};

extern ComputerManager gComputerManager;
#endif // COMPUTERMANAGER_H
